import { NodeSize } from '../config'

export default function execSql(flow) {
  flow.register('ExecSql', ({ PolygonNode, PolygonNodeModel, h }) => {
    class Node extends PolygonNode {
      getIconShape() {
        return h(
          'svg',
          {
            width: NodeSize,
            height: NodeSize,
            viewBox: '0 0 1024 1024'
          },
          h(
            'path',
            {
              fill: '#0CB20F',
              d: 'M662.162286 686.616381v271.335619l290.889143-135.484952-290.889143-135.850667z m45.104762 70.851048l139.068952 64.950857-139.068952 64.755809v-129.706666z'
            }
          ),
          h(
            'path',
            {
              fill: '#EFF9FE',
              d: 'M522.532571 427.471238c-19.163429 0-27.136 8.045714-27.136 21.942857v53.564953c0 13.897143 7.972571 21.942857 27.136 21.942857s27.136-8.045714 27.136-21.942857v-53.564953c0-13.897143-7.972571-21.942857-27.136-21.942857z'
            }
          ),
          h(
            'path',
            {
              fill: '#EFF9FE',
              d: 'M699.806476 283.89181h41.447619v27.233523h27.501715a47.299048 47.299048 0 0 0 47.201523-47.225904 47.274667 47.274667 0 0 0-47.201523-47.201524H411.526095c-58.709333 0-91.038476 32.329143-91.038476 91.038476v371.833905h150.235429v41.447619h-230.156191a47.274667 47.274667 0 0 0-47.201524 47.201524 47.299048 47.299048 0 0 0 47.201524 47.225904H506.148571l193.657905-193.657904V283.89181z m-291.547428 261.12c-12.604952 0-27.794286-2.364952-39.15581-6.948572l-2.096762-0.828952 3.730286-18.67581 2.876952 0.902095c11.50781 3.584 23.576381 5.485714 35.035429 5.485715 19.480381 0 22.162286-4.534857 22.162286-17.334857 0-4.169143 0-7.363048-0.438858-9.923048a8.045714 8.045714 0 0 0-2.194285-4.827429c-2.657524-2.608762-8.338286-4.388571-21.845334-7.460571-32.158476-7.192381-36.815238-14.165333-36.815238-42.154667 0-24.185905 10.800762-35.864381 43.76381-35.864381 11.385905 0 24.892952 1.536 35.376762 4.33981l2.218666 0.560762-1.852952 19.456-3.023238-0.682667c-9.99619-2.267429-21.942857-3.608381-32.329143-3.608381-20.065524 0-22.137905 3.535238-22.137905 16.359619 0 4.266667-0.024381 7.509333 0.365715 10.069334 0.365714 2.31619 0.975238 3.632762 2.023619 4.705523 2.535619 2.535619 7.850667 4.169143 20.992 7.460572 35.08419 8.704 37.912381 14.652952 37.912381 41.155047 0 23.917714-7.826286 37.814857-44.568381 37.814858z m163.425523-41.642667c0 18.627048-9.679238 34.791619-32.377904 39.789714l10.532571 23.820191-19.821714 8.996571-13.726476-31.256381c-30.037333-2.145524-42.910476-19.772952-42.910477-41.325714v-54.345143c0-23.04 14.677333-41.642667 49.152-41.642667 34.499048 0 49.152 18.602667 49.152 41.642667v54.320762z m102.13181 39.716571H596.114286v-133.753904h21.991619v113.493333h55.686095v20.260571z'
            }
          ),
          h(
            'path',
            {
              fill: '#3D6480',
              d: 'M193.365333 768.219429c0-26.014476 21.187048-47.201524 47.201524-47.201524h230.13181v-41.447619h-150.235429V307.736381c0-58.709333 32.329143-91.038476 91.038476-91.038476H768.731429c26.014476 0 47.201524 21.187048 47.201523 47.201524a47.299048 47.299048 0 0 1-47.201523 47.225904h-27.501715v-27.233523h-41.447619v337.92l41.447619-41.44762v-227.791238h27.501715a88.746667 88.746667 0 0 0 88.649142-88.673523 88.746667 88.746667 0 0 0-88.649142-88.649143H411.526095c-81.724952 0-132.486095 50.785524-132.486095 132.486095v371.833905H240.566857a88.746667 88.746667 0 0 0-88.649143 88.649143 88.746667 88.746667 0 0 0 88.649143 88.673523h224.134095l41.447619-41.447619H240.566857a47.250286 47.250286 0 0 1-47.201524-47.225904z'
            }
          ),
          h(
            'path',
            {
              fill: '#3D6480',
              d: 'M414.915048 466.066286c-13.141333-3.291429-18.480762-4.924952-20.992-7.460572-1.048381-1.072762-1.657905-2.413714-2.023619-4.705524-0.390095-2.56-0.365714-5.802667-0.365715-10.069333 0-12.824381 2.072381-16.359619 22.137905-16.359619 10.386286 0 22.332952 1.340952 32.329143 3.608381l3.023238 0.682667 1.852952-19.456-2.218666-0.560762a148.138667 148.138667 0 0 0-35.376762-4.33981c-32.963048 0-43.76381 11.678476-43.76381 35.864381 0 27.989333 4.632381 34.962286 36.815238 42.154667 13.531429 3.072 19.18781 4.827429 21.845334 7.460571a8.118857 8.118857 0 0 1 2.194285 4.827429c0.438857 2.56 0.438857 5.753905 0.438858 9.923048 0 12.8-2.681905 17.334857-22.162286 17.334857a118.491429 118.491429 0 0 1-35.035429-5.485715l-2.876952-0.902095-3.730286 18.67581 2.096762 0.828952c11.385905 4.583619 26.575238 6.948571 39.15581 6.948571 36.742095 0 44.544-13.897143 44.544-37.790476 0.024381-26.550857-2.80381-32.475429-37.888-41.179428zM522.532571 407.405714c-34.474667 0-49.152 18.602667-49.152 41.642667v54.345143c0 21.552762 12.848762 39.18019 42.910477 41.325714l13.726476 31.256381 19.821714-8.996571-10.532571-23.820191c22.698667-4.998095 32.377905-21.162667 32.377904-39.789714v-54.345143c0-23.04-14.652952-41.618286-49.152-41.618286z m27.136 95.573334c0 13.897143-7.972571 21.942857-27.136 21.942857s-27.136-8.045714-27.136-21.942857v-53.564953c0-13.897143 7.972571-21.942857 27.136-21.942857s27.136 8.045714 27.136 21.942857v53.564953zM618.130286 409.33181h-22.016v133.753904h77.702095v-20.260571h-55.686095z'
            }
          )
        )
      }

      getLabelShape() {
        return h(
          'text',
          {
            fill: '#000000',
            fontSize: 12,
            x: NodeSize / 2,
            y: NodeSize + 20,
            textAnchor: 'middle',
            dominantBaseline: 'middle'
          },
          '执行SQL脚本'
        )
      }

      getShape() {
        const { x, y, width, height } = this.getAttributes()
        const transform = `matrix(1 0 0 1 ${x - width / 2} ${y - height / 2})`
        return h(
          'g',
          {
            transform
          },
          [
            h(
              'rect',
              {
                rx: 5,
                ry: 5,
                width: NodeSize,
                height: NodeSize,
                fill: '#fff',
                stroke: '#3D6380',
                strokeWidth: 1
              }
            ),
            this.getIconShape(),
            this.getLabelShape()
          ]
        )
      }
    }
    class Model extends PolygonNodeModel {
      constructor(data, graphModel) {
        super(data, graphModel)
        this.points = [
          [NodeSize / 2, 0],
          [NodeSize, NodeSize / 2],
          [NodeSize / 2, NodeSize],
          [0, NodeSize / 2]
        ]
      }
    }

    return {
      view: Node,
      model: Model
    }
  })
}
